import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 通过 defineStore 定义数据仓库，返回获取仓库的函数，命名一般是 useXxxStore
export const useCounterStore = defineStore("counter", () => {
  // states 数据
  const totalCount = ref(0)

  // actions 修改方法
  const addTotalCount = (value: number) => {
    totalCount.value += value
  }

  // getters 计算属性
  const doubleTotalCount = computed(() => {
    return totalCount.value * 2
  })

  // 返回数据
  return { totalCount, addTotalCount, doubleTotalCount }
}, {
  persist: true
})